﻿#region License
//
//  Copyright (c) 2012 Shawn Rakowski
//
//  Permission is hereby granted, free of charge, to any person obtaining a copy of 
//  this software and associated documentation files (the "Software"), to deal in the 
//  Software without restriction, including without limitation the rights to use, copy, 
//  modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 
//  and to permit persons to whom the Software is furnished to do so, subject to the 
//  following conditions:
//
//  The above copyright notice and this permission notice shall be included in all 
//  copies or substantial portions of the Software.
//
//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 
//  INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 
//  PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 
//  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 
//  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 
//  SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#endregion

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace ERMAHGERD.Tests
{
    [TestClass]
    public class TranslateTest
    {
        [TestMethod]
        public void TestOhMyGodResultsInErMahGerd()
        {
            var result = Translate.ToErMahGerd("oh");
            Assert.AreEqual("ER", result);
            result = Translate.ToErMahGerd("my");
            Assert.AreEqual("MAH", result);
            result = Translate.ToErMahGerd("god");
            Assert.AreEqual("GERD", result);

            result = Translate.ToErMahGerd("ERMAHGERD");
            Assert.AreEqual("ERMAHGERD", result);

            result = Translate.ToErMahGerd("OMG");
            Assert.AreEqual("ERMAHGERD", result);
        }

        [TestMethod]
        public void TestSoloVowelsReturnERExceptOnUAndY()
        {
            Assert.AreEqual("ER", Translate.ToErMahGerd("A"));
            Assert.AreEqual("ER", Translate.ToErMahGerd("E"));
            Assert.AreEqual("ER", Translate.ToErMahGerd("I"));
            Assert.AreEqual("ER", Translate.ToErMahGerd("O"));
            Assert.AreEqual("U", Translate.ToErMahGerd("U"));
            Assert.AreEqual("Y", Translate.ToErMahGerd("Y"));
        }

        [TestMethod]
        public void TestVarietyOfWords()
        {
            var result = Translate.ToErMahGerd("father");
            Assert.AreEqual("FERTHER", result);
            result = Translate.ToErMahGerd("doll");
            Assert.AreEqual("DERL", result);
            result = Translate.ToErMahGerd("bat");
            Assert.AreEqual("BERT", result);
            result = Translate.ToErMahGerd("made");
            Assert.AreEqual("MERD", result);
            result = Translate.ToErMahGerd("bought");
            Assert.AreEqual("BERGHT", result);
            result = Translate.ToErMahGerd("me");
            Assert.AreEqual("MAH", result);
            result = Translate.ToErMahGerd("the");
            Assert.AreEqual("DA", result);
            result = Translate.ToErMahGerd("they");
            Assert.AreEqual("DEY", result);
            result = Translate.ToErMahGerd("tiny");
            Assert.AreEqual("TERNER", result);
            result = Translate.ToErMahGerd("winner");
            Assert.AreEqual("WERNER", result);
            result = Translate.ToErMahGerd("fancy");
            Assert.AreEqual("FERNCER", result);
            result = Translate.ToErMahGerd("hey");
            Assert.AreEqual("HER", result);
            result = Translate.ToErMahGerd("midget");
            Assert.AreEqual("MERDGERT", result);
        }

        [TestMethod]
        public void TestUReturnsU()
        {
            var result = Translate.ToErMahGerd("you");
            Assert.AreEqual("U", result);
        }

        [TestMethod]
        public void TestINGAtEndOfWordProducesIN()
        {
            var result = Translate.ToErMahGerd("typing");
            Assert.AreEqual("TERPIN", result);
            result = Translate.ToErMahGerd("paying");
            Assert.AreEqual("PERIN", result);
            result = Translate.ToErMahGerd("swinging");
            Assert.AreEqual("SWERNGIN", result);
        }

        [TestMethod]
        public void TestESAtEndOfWordProducesS()
        {
            Assert.AreEqual("BERKS", Translate.ToErMahGerd("bikes"));
            Assert.AreEqual("MERKS", Translate.ToErMahGerd("makes"));
            Assert.AreEqual("TIRS", Translate.ToErMahGerd("tires"));
            Assert.AreEqual("CERS", Translate.ToErMahGerd("cares"));
            Assert.AreEqual("BERS", Translate.ToErMahGerd("bees"));

            // exceptions
            Assert.AreEqual("KERSERS", Translate.ToErMahGerd("kisses")); // ses
            Assert.AreEqual("FERSHERS", Translate.ToErMahGerd("fishes")); // shes
        }

        [TestMethod]
        public void TestIEAtEndOfWordProducesER()
        {
            Assert.AreEqual("CERER", Translate.ToErMahGerd("carrie"));
            Assert.AreEqual("MERER", Translate.ToErMahGerd("marie"));
            Assert.AreEqual("BERGER", Translate.ToErMahGerd("biggie"));
            Assert.AreEqual("CERKER", Translate.ToErMahGerd("COOKIE"));
        }

        [TestMethod]
        public void Test2LetterWordsEndingWithVowelsReturnCorrectly()
        {
            var result = Translate.ToErMahGerd("to");
            Assert.AreEqual("TER", result);
            result = Translate.ToErMahGerd("be");
            Assert.AreEqual("BER", result);
        }

        [TestMethod]
        public void TestWordsEndingWithAIO()
        {
            var result = Translate.ToErMahGerd("toga");
            Assert.AreEqual("TERGER", result);
            result = Translate.ToErMahGerd("yoga");
            Assert.AreEqual("YERGER", result);
            result = Translate.ToErMahGerd("america");
            Assert.AreEqual("ERMERERCER", result);
            result = Translate.ToErMahGerd("potato");
            Assert.AreEqual("PERTERTER", result);
            result = Translate.ToErMahGerd("ricki");
            Assert.AreEqual("RERCKER", result);
        }

        [TestMethod]
        public void TestVowelsFollowedByRAreKeptExceptAAndY()
        {
            var result = Translate.ToErMahGerd("starts");
            Assert.AreEqual("STERTS", result);
            result = Translate.ToErMahGerd("adventure");
            Assert.AreEqual("ERDVERNTUR", result);
            result = Translate.ToErMahGerd("byrd");
            Assert.AreEqual("BERD", result);
        }

        [TestMethod]
        public void TestWithPunctuation()
        {
            var result = Translate.ToErMahGerd("here!");
            Assert.AreEqual("HER!", result);
            Assert.AreEqual("WER'RER", Translate.ToErMahGerd("we're"));
            Assert.AreEqual("WERN'T", Translate.ToErMahGerd("won't"));

        }

        [TestMethod]
        public void TestCommonPhrases()
        {
            var result = Translate.ToErMahGerd("goosebumps my favorite books");
            Assert.AreEqual("GERSBERMS MAH FRAVRIT BERKS", result);
            result = Translate.ToErMahGerd("choose your own adventure");
            Assert.AreEqual("CHERS YUR ERN ERDVERNTUR", result);
        }
    }
}
